/*
******************************************************************************
*
*   Copyright (C) 1999-2007, International Business Machines
*   Corporation and others.  All Rights Reserved.
*
******************************************************************************/


/*----------------------------------------------------------------------------
 *
 *       Memory mapped file wrappers for use by the ICU Data Implementation
 *       All of the platform-specific implementation for mapping data files
 *         is here.  The rest of the ICU Data implementation uses only the
 *         wrapper functions.
 *
 *----------------------------------------------------------------------------*/

/* Needed by OSF and z/OS to get the correct mmap version */
#if !defined(_XOPEN_SOURCE_EXTENDED)
#define _XOPEN_SOURCE_EXTENDED 1
#endif

#include "udatamem.h"
#include "umapfile.h"
#include "local.h"

/* memory-mapping base definitions ------------------------------------------ */


/*----------------------------------------------------------------------------*
 *                                                                            *
 *   Memory Mapped File support.  Platform dependent implementation of        *
 *                           functions used by the rest of the implementation.*
 *                                                                            *
 *----------------------------------------------------------------------------*/
UBool uprv_mapFile(UDataMemory *pData, const char *path) {
    void *p = NULL;
	UDataMemory_init(pData); /* Clear the output struct.        */
	p = icupub_ReadFile(path);
	if (p == NULL)
		return FALSE;

	pData->map=p;
	pData->pHeader=(const DataHeader *)p;
	pData->mapAddr=p;
	return TRUE;
}

void uprv_unmapFile(UDataMemory *pData) {
    if(pData!=NULL && pData->map!=NULL) {
        free(pData->map);
        pData->map     = NULL;
        pData->mapAddr = NULL;
        pData->pHeader = NULL;
    }
}
